/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package User.DataLayer;

import DataModel.*;
import Utilities.*;
import java.sql.ResultSet;
import java.util.LinkedList;

/**
 *
 * @author Rainiero
 */
public class UserDataManager {

    // <editor-fold defaultstate="collapsed" desc="Singleton">
    private static UserDataManager _instance = new UserDataManager();

    private UserDataManager()
    {
    }

    public static UserDataManager GetInstance()
    {
        return _instance;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Public Methods">
    public PersonSummary[] GetUsersInRole(Enums.UserRole role)
    {
        DataAccesor accesor = DataAccesor.GetInstance();
        String spName = "ObtenerUsuarios";
        SQLParameter[] parameters = new SQLParameter[]
        {
            new SQLParameter("tipoUsuario", EnumConverter.GetEnumName(role))
        };
        try
        {
            ResultSet reader = accesor.ExecuteInputSP(spName, parameters);
            LinkedList<PersonSummary> result = new LinkedList<PersonSummary>();
            while(reader.next())
            {
                int id = reader.getInt("IdUsuario");
                String name = reader.getString("NombrePersona");
                String lastName1 = reader.getString("PrimerApellido");
                String lastName2 = reader.getString("SegundoApellido");
                PersonSummary person = new PersonSummary(id, name, lastName1, lastName2);
                result.add(person);
            }
            reader.close();
            PersonSummary[] resultArray = new PersonSummary[result.size()];
            return result.toArray(resultArray);
        }
        catch(Exception ex)
        {
            return null;
        }
    }
    // </editor-fold>

}
